package com.moore.thread;

import com.moore.utils.ThreadPoolUtils;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class AcceptThread extends Thread{
    public void run(){
        try {
            // 创建服务器：端口10086 协议TCP 建立监听
            ServerSocket serverSocket = new ServerSocket(10086);
            // 循环请求与响应
            while (true) {
                // 阻塞等待客户端连接
                Socket socket = serverSocket.accept();
                SocketThread socketThread = new SocketThread(socket);
                // 使用线程池执行线程
                ThreadPoolUtils.getInstance().execute(socketThread);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
